package com.mayikt.main.api.impl.producer;

import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;


@Component
@Slf4j
public class LoginProducer {
    @Autowired
    private AmqpTemplate amqpTemplate;
    @Autowired
    private BatchDeliveryBuffer batchDeliveryBuffer;

    /**
     * 登录后续处理流程
     */
    public void sendLoginFollowUp(Integer userId, String loginIp, Date loginTime, String loginToken,
                                  String channel, String equipment) {
        /**
         * 1.交换机名称
         * 2.路由key名称
         * 3.发送内容
         */
        JSONObject data = new JSONObject();
        data.put("userId", userId);
        data.put("loginIp", loginIp);
        data.put("loginTime", loginTime);
        data.put("loginToken", loginToken);
        data.put("channel", channel);
        data.put("equipment", equipment);
        //生成全局id uuid
        data.put("messageId", UUID.randomUUID());
        batchDeliveryBuffer.addBuffer(data);
//        data.put("openId", openid);
//        data.put("phone", phone);
        //  String dataJSON = data.toJSONString();
        //     amqpTemplate.convertAndSend("/mayikt_ex", "", dataJSON);
        //  log.info(">>登录之后投递mq消息，异步处理后续操作..dataJSON:{}<<", dataJSON);
    }
}
